package com.wu.error;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-04-19 21:31
 */
public class BusinessException extends RuntimeException implements CommonError {
    private static final long serialVersionUID = 573845796429957366L;

    private CommonError commonError;

    /**
     * 直接接收EnumBusinessError的传参，用于构造业务异常
     *
     * @param commonError
     */
    public BusinessException(CommonError commonError) {
        super();
        this.commonError = commonError;
    }

    /**
     * 接收自定义errorMsg的方式构造业务异常
     *
     * @param commonError
     * @param errorMsg
     */
    public BusinessException(CommonError commonError, String errorMsg) {
        super();
        this.commonError = commonError;
        this.commonError.setErrorMsg(errorMsg);
    }


    @Override
    public int getErrorCode() {
        return this.commonError.getErrorCode();
    }

    @Override
    public String getErrorMsg() {
        return this.commonError.getErrorMsg();
    }

    @Override
    public CommonError setErrorMsg(String errorMsg) {
        this.commonError.setErrorMsg(errorMsg);
        return this;
    }
}
